{{!
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at
  
       http://www.apache.org/licenses/LICENSE-2.0
  
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
}}

<div class="edit-script">
    <div {{bind-attr class=":panel :panel-editscript scriptError:panel-danger:panel-default"}} >
      <div class="panel-heading">
        <div class="head control-group">
            {{outlet nav}}
            {{#unless isRenaming}}
              <div  {{bind-attr class="controller.isScript:input-group :input-title"}}>
                {{input id="title" placeholderTranslation="scripts.title" class="form-control" disabled='disabled' valueBinding="content.title"}}
                <div {{bind-attr class=":input-group-btn controller.isJob:hide"}}>
                  <button  type="button" {{action 'rename' 'ask'}} {{bind-attr class=":btn :btn-default :btn-rename-ask"}} >
                    <span class="glyphicon glyphicon-edit"></span>
                  </button>
                </div>
              </div>
            {{else}}
              <div  {{bind-attr class=":input-group :input-title"}}>
                {{input id="title" placeholderTranslation="scripts.title" class="form-control" valueBinding="content.title"}}
                <div class="input-group-btn">
                  <button  type="button" {{action 'rename' 'cancel'}} {{bind-attr class=":btn :btn-default :btn-rename-cancel"}} >
                    <span class="glyphicon glyphicon-remove"></span> {{t 'common.cancel'}}
                  </button>
                </div>
                <div class="input-group-btn">
                  <button  type="button" {{action 'rename' 'confirm'}} {{bind-attr class=":btn :btn-primary :btn-rename-confirm"}} >
                    <span class="glyphicon glyphicon-ok"></span> {{t 'editor.save'}}
                  </button>
                </div>
              </div>
            {{/unless}}
        </div>
      </div>
      {{#if view.showEditor}}
      <div class="panel-body" >
        <div class="pull-left">
        {{#if view.isEditConfirmed}}
          {{view view.pigHelperView class="btn-group" }}
          <div class="btn-group">
              <button type="button" data-toggle="dropdown" {{bind-attr class=":btn :btn-default :btn-xs :dropdown-toggle ufdsList.length::disabled"}} >
                {{t 'editor.udfhelper'}}
                <span class="caret"></span>
              </button>
              <ul class="dropdown-menu">
              {{#each ufdsList}}
                <li><a href="#" {{action 'insertUdf' this target="view" }}>{{this.name}}</a></li>
              {{/each}}
              </ul>
          </div>
        {{/if}}
        </div>
        <kbd class="file-path pull-right" data-toggle="tooltip" data-placement="bottom"{{translateAttr title="udfs.tooltips.path"}} >
          {{#unless content.pigScript.isLoaded}}
            <div class="spinner-sm"></div>
          {{/unless}}
          {{#if content.pigScript.isLoaded}}
            {{content.pigScript.id}}
          {{/if}}
        </kbd>
      </div>
      <div class="editor-container">
        {{#if controller.isJob}}
          {{#unless view.isEditConfirmed}}
            <div class="edit-confirm">
              <div class="well edit-confirm-container">
                When you executed job, script was copied to another place in filesystem. <br />
                You're going to edit the <u>copy of original script</u> from history<br />
                <button {{action "confirmEdit" target="view"}} class="btn btn-large" type="button">Edit script from history</button>
                {{#if content.scriptId}}
                  <button {{action "returnToOriginal" content}} class="btn btn-large btn-primary" type="button">Return to original file</button>
                {{/if}}
              </div>
            </div>
          {{/unless}}
        {{/if}}
        {{view view.codeMirrorView id="pig_script" contentBinding="content.pigScript"}}
      </div>
      <div class="panel-footer" >
        <span>
          {{#with controller}}
            {{#each controller.pigArgumentsPull}}
              <span {{bind-attr class=":argument controller.isScript:editable:"}} >
                <span class="title"> {{this}} </span>
                {{#if controller.isScript}}
                <button {{action "removeArgument" this}}  class="close rm-arg">
                    &times;
                </button>
                {{/if}}
              </span>
            {{/each}}
          {{/with}}
          {{#if controller.isScript}}
          {{view view.argumentInput placeholderTranslation="editor.pig_argument"}}
            <button {{action "sendArgument" target="view.argumentInput" }} type="button" {{bind-attr class=":btn :btn-default :btn-xs view.argumentInput.value::disabled"}}>
              <span class="glyphicon glyphicon-plus"></span> {{t 'common.add'}}
            </button>
          {{/if}}
        </span>
      </div>
      {{else}}
      <table class="table table-results">
        <tr>
          <td>{{t 'common.path'}}:</td>
          <td><kbd>{{content.pigScript.id}}</kbd></td>
        </tr>
        <tr>
          <td>{{t 'job.started'}}:</td>
          <td>{{showDate content.dateStarted 'YYYY-MM-DD HH:mm'}}</td>
        </tr>
        <tr>
          <td>{{t 'common.arguments'}}:</td>
          <td>
            {{#each pigArgumentsPull}}
              <span {{bind-attr class=":argument controller.isScript:editable:"}} >
                <span class="title"> {{this}} </span>
              </span>
            {{/each}}
          </td>
        </tr>
      </table>
      {{/if}}

    </div>

    {{outlet main}}

    <div class="form-inline pigParams">
    {{#each pigParams}}
    <div class="form-group">
      <label class="control-label">{{this.title}}</label>
      <div class="">
       {{view view.pigParamView class='form-control input-sm' valueBinding='value'}}
      </div>
    </div>
    {{/each}}
    </div>
    {{#if view.showEditor}}
    <div class="controls">
      {{#unless isExec}}
        <button {{action "execute" content 'execute' }} type="button" class="btn btn-default">{{t 'editor.execute'}}</button>
        <button {{action "execute" content 'explain' }} type="button" class="btn btn-default">{{t 'editor.explain'}}</button>
        <button {{action "execute" content 'syntax_check' }} type="button" class="btn btn-default">{{t 'editor.syntax_check'}}</button>
        <input type="button" {{action "saveScript" content}} {{bind-attr class=":btn :btn-primary scriptDirty::disabled"}} {{translateAttr value="editor.save"}} >
      {{/unless}}

      {{#if isExec}}
        <div class="spinner-sm"></div>
      {{/if}}
    </div>
    {{/if}}
</div>
